export class Camera {
  private x: number = 0;
  private y: number = 0;
  private zoom: number = 1;
  private rotation: number = 0;

  constructor(
    public width: number,
    public height: number
  ) {}

  setPosition(x: number, y: number): void {
    this.x = x;
    this.y = y;
  }

  setZoom(zoom: number): void {
    this.zoom = Math.max(0.1, zoom);
  }

  setRotation(angle: number): void {
    this.rotation = angle;
  }

  applyTransform(context: CanvasRenderingContext2D): void {
    context.translate(this.width / 2, this.height / 2);
    context.scale(this.zoom, -this.zoom);
    context.rotate(this.rotation);
    context.translate(-this.x, -this.y);
  }

  worldToScreen(x: number, y: number): { x: number; y: number } {
    return {
      x: (x - this.x) * this.zoom + this.width / 2,
      y: (y - this.y) * this.zoom + this.height / 2
    };
  }

  screenToWorld(x: number, y: number): { x: number; y: number } {
    return {
      x: (x - this.width / 2) / this.zoom + this.x,
      y: (y - this.height / 2) / this.zoom + this.y
    };
  }
}
